#include "stm32_common.h"
#include "forco_os.h"
#include "cpu.h"

extern void OS_SystickInit(CPU_UINT32 ms);
extern void OSStartHighRdy(void);


//任务堆栈大小
#define  TASKSTKSIZE       512
//任务栈
CPU_UINT8 task1stk[TASKSTKSIZE];
CPU_UINT8 task2stk[TASKSTKSIZE];
CPU_UINT8 task3stk[TASKSTKSIZE];
//任务控制块
OS_TCB  task1tcb;
OS_TCB  task2tcb;
OS_TCB  task3tcb;

extern void OSSched(void);
extern OS_TCB      *OSTCBHighRdyPtr;
extern OS_TCB      *OSTCBCurPtr;

void forco_taskled1blink(void *arg)
{
    for(;;)
    {
        Forco_BspLEDToggle(LED1);
        OSTimeDly(100);
    }
}

void forco_taskled2blink(void *arg)
{
    for(;;)
    {
          Forco_BspLEDToggle(LED2);
          OSTimeDly(200);
    }
}

void forco_taskled3blink(void *arg)
{
    for(;;)
    {
          Forco_BspLEDToggle(LED3);
          OSTimeDly(300);
    }
}


int main(void)
{
  OS_ERR err;
  __asm("cpsid i");
  Forco_BspInit();
  OSInit();
  OSTaskCreateStatic(&task1tcb,forco_taskled1blink,NULL,"taskled1",1,(CPU_UINT32*)&task1stk[0],TASKSTKSIZE,&err);
  OSTaskCreateStatic(&task2tcb,forco_taskled2blink,NULL,"taskled2",2,(CPU_UINT32*)&task2stk[0],TASKSTKSIZE,&err);
  OSTaskCreateStatic(&task3tcb,forco_taskled3blink,NULL,"taskled3",3,(CPU_UINT32*)&task3stk[0],TASKSTKSIZE,&err);
  OS_SystickInit(1);
  OSStartRun();
  while(1);
}
